package com.lagou.email.serivce;

import com.lagou.email.common.MailBean;
import com.lagou.email.common.SendEmail;
import lagou.service.api.service.EmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * Created with IntelliJ IDEA by ChouFy on 2020-06-05.
 *
 * @author chouFy
 */
@Service
public class EmailServiceImpl  implements EmailService {

    @Autowired
    private SendEmail sendEmail;

    @Override
    public boolean email(String email, String code) {


        MailBean mb = new MailBean();
        // 设置SMTP主机(163)，若用126，则设为：smtp.126.com
        mb.setHost("smtp.qiye.163.com");
        // 设置发件人邮箱的用户名
        mb.setUsername("support@ronghuijinfubj.com");
        // 设置发件人邮箱的密码，需将*号改成正确的密码
        mb.setPassword("qiye@163");
        // 设置发件人的邮箱
        mb.setFrom(email);

        // 设置邮件的主题
        mb.setSubject("注册验证码");
        // 设置邮件的正文
        mb.setContent(code);

        System.out.println("正在发送邮件..." + email);
        // 发送邮件
        boolean b = sendEmail.sendMail(mb);
        if (b) {
            System.out.println("发送成功!");

        } else {
            System.out.println("发送失败!");

        }
        return b;
    }

}
